
#pragma once

#include "zen_vap.h"
#include "Ctrl.hpp"
#include "VPlayArea.hpp"

class MainDelegate : public Zen::Vap::RootDelegate {
	float fps = 0;
	int nth = 0;
	// use shared_ptr pointer....
//	weak_ptr<RootScene2d> m_s2D;
//	weak_ptr<RootScene3d> m_s3D;
	std::shared_ptr<Scene2D> m_scene;
public:

	virtual void onLaunch(Zen::Size2 view_size) override
	{
		Zen::App::Get()->setMultiTouch(false);
		Zen::App::Get()->setFramesPerSecond(60);
		Zen::App::Get()->setRotatable(true);
		VConfigs::Get()->initViewSize(Zen::Vap::Activity::Get()->getRealViewSize());

		auto size = VConfigs::Get()->getViewSize();

		LogV("ScreenSize: %.2f %.2f", size.w, size.h);

		auto scene = std::make_shared<Scene2D>();
		Activity::Get()->getRootNode()->addNode(scene);

		// scene->projectView(0, gConfig.size.h, gConfig.size.w, -gConfig.size.h);
		scene->projectView(0, 0, size.w, size.h);

		m_scene = scene;

		this->loadSource();

		this->loadView();

		Ctrl::Get()->startGame();
	}
	void loadSource()
	{
		auto font_data = Zen::Utils::Get()->loadResource(GetPath("font0"));
		Zen::FontCache::Get()->cacheFont("font0", Zen::Font::Create(font_data));

		VConfigs::Get()->font_brush_normal = Zen::FontBrush::Create(Zen::FontCache::Get()->getFont("font0"), 64);
	}
	void loadView()
	{
		auto pa = std::make_shared<VPlayArea>();
		m_scene->addNode(pa);

		Ctrl::Get()->setCurrentViewPlay(pa);
	}

	virtual void onTouchDown(AppTouch touch) override {
		
	}

	virtual void onTouchMove(AppTouch touch) override {}

};

//class ViewCtrl
//{
//public:
//	virtual void onEvent(std::string const & name)
//};
